package com.example.singing.model;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 系统配置模型类
 * 包含系统的各种配置选项
 */
public class SystemConfig implements Serializable {
    private static final long serialVersionUID = 1L;
    
    // 界面主题设置
    private String theme = "light"; // light, dark, auto
    private String primaryColor = "#673ab7";
    private String accentColor = "#ff4081";
    private boolean enableAnimations = true;
    private boolean enableSoundEffects = true;
    
    // 评分系统设置
    private int defaultJudgeCount = 5;
    private double minScore = 0.0;
    private double maxScore = 100.0;
    private boolean enableSmartScoring = true;
    private boolean enableScoreValidation = true;
    private boolean showDetailedScores = true;
    
    // 数据管理设置
    private boolean autoBackup = true;
    private int backupInterval = 24; // 小时
    private int maxBackupFiles = 10;
    private boolean enableDataCompression = true;
    private boolean enableDataEncryption = false;
    
    // 系统安全设置
    private boolean requirePasswordChange = false;
    private int passwordMinLength = 6;
    private int sessionTimeout = 30; // 分钟
    private boolean enableLoginLogging = true;
    private boolean enableAuditTrail = true;
    
    // 通知设置
    private boolean enableEmailNotifications = false;
    private String emailSmtpHost = "";
    private int emailSmtpPort = 587;
    private String emailUsername = "";
    private String emailPassword = "";
    private boolean enableSystemNotifications = true;
    
    // 高级功能设置
    private boolean enableAIAnalysis = true;
    private boolean enableRealTimeSync = false;
    private boolean enableCloudBackup = false;
    private String cloudProvider = "none"; // none, aws, azure, gcp
    private boolean enablePerformanceMonitoring = true;
    
    // 系统信息
    private LocalDateTime lastModified = LocalDateTime.now();
    private String version = "1.0.0";
    private List<String> recentBackups = new ArrayList<>();
    private List<String> systemLogs = new ArrayList<>();
    
    // 默认构造函数
    public SystemConfig() {
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for Theme Settings
    public String getTheme() { return theme; }
    public void setTheme(String theme) { 
        this.theme = theme; 
        this.lastModified = LocalDateTime.now();
    }
    
    public String getPrimaryColor() { return primaryColor; }
    public void setPrimaryColor(String primaryColor) { 
        this.primaryColor = primaryColor; 
        this.lastModified = LocalDateTime.now();
    }
    
    public String getAccentColor() { return accentColor; }
    public void setAccentColor(String accentColor) { 
        this.accentColor = accentColor; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableAnimations() { return enableAnimations; }
    public void setEnableAnimations(boolean enableAnimations) { 
        this.enableAnimations = enableAnimations; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableSoundEffects() { return enableSoundEffects; }
    public void setEnableSoundEffects(boolean enableSoundEffects) { 
        this.enableSoundEffects = enableSoundEffects; 
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for Scoring Settings
    public int getDefaultJudgeCount() { return defaultJudgeCount; }
    public void setDefaultJudgeCount(int defaultJudgeCount) { 
        this.defaultJudgeCount = defaultJudgeCount; 
        this.lastModified = LocalDateTime.now();
    }
    
    public double getMinScore() { return minScore; }
    public void setMinScore(double minScore) { 
        this.minScore = minScore; 
        this.lastModified = LocalDateTime.now();
    }
    
    public double getMaxScore() { return maxScore; }
    public void setMaxScore(double maxScore) { 
        this.maxScore = maxScore; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableSmartScoring() { return enableSmartScoring; }
    public void setEnableSmartScoring(boolean enableSmartScoring) { 
        this.enableSmartScoring = enableSmartScoring; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableScoreValidation() { return enableScoreValidation; }
    public void setEnableScoreValidation(boolean enableScoreValidation) { 
        this.enableScoreValidation = enableScoreValidation; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isShowDetailedScores() { return showDetailedScores; }
    public void setShowDetailedScores(boolean showDetailedScores) { 
        this.showDetailedScores = showDetailedScores; 
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for Data Management Settings
    public boolean isAutoBackup() { return autoBackup; }
    public void setAutoBackup(boolean autoBackup) { 
        this.autoBackup = autoBackup; 
        this.lastModified = LocalDateTime.now();
    }
    
    public int getBackupInterval() { return backupInterval; }
    public void setBackupInterval(int backupInterval) { 
        this.backupInterval = backupInterval; 
        this.lastModified = LocalDateTime.now();
    }
    
    public int getMaxBackupFiles() { return maxBackupFiles; }
    public void setMaxBackupFiles(int maxBackupFiles) { 
        this.maxBackupFiles = maxBackupFiles; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableDataCompression() { return enableDataCompression; }
    public void setEnableDataCompression(boolean enableDataCompression) { 
        this.enableDataCompression = enableDataCompression; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableDataEncryption() { return enableDataEncryption; }
    public void setEnableDataEncryption(boolean enableDataEncryption) { 
        this.enableDataEncryption = enableDataEncryption; 
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for Security Settings
    public boolean isRequirePasswordChange() { return requirePasswordChange; }
    public void setRequirePasswordChange(boolean requirePasswordChange) { 
        this.requirePasswordChange = requirePasswordChange; 
        this.lastModified = LocalDateTime.now();
    }
    
    public int getPasswordMinLength() { return passwordMinLength; }
    public void setPasswordMinLength(int passwordMinLength) { 
        this.passwordMinLength = passwordMinLength; 
        this.lastModified = LocalDateTime.now();
    }
    
    public int getSessionTimeout() { return sessionTimeout; }
    public void setSessionTimeout(int sessionTimeout) { 
        this.sessionTimeout = sessionTimeout; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableLoginLogging() { return enableLoginLogging; }
    public void setEnableLoginLogging(boolean enableLoginLogging) { 
        this.enableLoginLogging = enableLoginLogging; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableAuditTrail() { return enableAuditTrail; }
    public void setEnableAuditTrail(boolean enableAuditTrail) { 
        this.enableAuditTrail = enableAuditTrail; 
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for Notification Settings
    public boolean isEnableEmailNotifications() { return enableEmailNotifications; }
    public void setEnableEmailNotifications(boolean enableEmailNotifications) { 
        this.enableEmailNotifications = enableEmailNotifications; 
        this.lastModified = LocalDateTime.now();
    }
    
    public String getEmailSmtpHost() { return emailSmtpHost; }
    public void setEmailSmtpHost(String emailSmtpHost) { 
        this.emailSmtpHost = emailSmtpHost; 
        this.lastModified = LocalDateTime.now();
    }
    
    public int getEmailSmtpPort() { return emailSmtpPort; }
    public void setEmailSmtpPort(int emailSmtpPort) { 
        this.emailSmtpPort = emailSmtpPort; 
        this.lastModified = LocalDateTime.now();
    }
    
    public String getEmailUsername() { return emailUsername; }
    public void setEmailUsername(String emailUsername) { 
        this.emailUsername = emailUsername; 
        this.lastModified = LocalDateTime.now();
    }
    
    public String getEmailPassword() { return emailPassword; }
    public void setEmailPassword(String emailPassword) { 
        this.emailPassword = emailPassword; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableSystemNotifications() { return enableSystemNotifications; }
    public void setEnableSystemNotifications(boolean enableSystemNotifications) { 
        this.enableSystemNotifications = enableSystemNotifications; 
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for Advanced Features
    public boolean isEnableAIAnalysis() { return enableAIAnalysis; }
    public void setEnableAIAnalysis(boolean enableAIAnalysis) { 
        this.enableAIAnalysis = enableAIAnalysis; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableRealTimeSync() { return enableRealTimeSync; }
    public void setEnableRealTimeSync(boolean enableRealTimeSync) { 
        this.enableRealTimeSync = enableRealTimeSync; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnableCloudBackup() { return enableCloudBackup; }
    public void setEnableCloudBackup(boolean enableCloudBackup) { 
        this.enableCloudBackup = enableCloudBackup; 
        this.lastModified = LocalDateTime.now();
    }
    
    public String getCloudProvider() { return cloudProvider; }
    public void setCloudProvider(String cloudProvider) { 
        this.cloudProvider = cloudProvider; 
        this.lastModified = LocalDateTime.now();
    }
    
    public boolean isEnablePerformanceMonitoring() { return enablePerformanceMonitoring; }
    public void setEnablePerformanceMonitoring(boolean enablePerformanceMonitoring) { 
        this.enablePerformanceMonitoring = enablePerformanceMonitoring; 
        this.lastModified = LocalDateTime.now();
    }
    
    // Getters and Setters for System Info
    public LocalDateTime getLastModified() { return lastModified; }
    public void setLastModified(LocalDateTime lastModified) { this.lastModified = lastModified; }
    
    public String getVersion() { return version; }
    public void setVersion(String version) { this.version = version; }
    
    public List<String> getRecentBackups() { return recentBackups; }
    public void setRecentBackups(List<String> recentBackups) { this.recentBackups = recentBackups; }
    
    public List<String> getSystemLogs() { return systemLogs; }
    public void setSystemLogs(List<String> systemLogs) { this.systemLogs = systemLogs; }
    
    /**
     * 添加系统日志
     */
    public void addSystemLog(String log) {
        if (systemLogs == null) {
            systemLogs = new ArrayList<>();
        }
        systemLogs.add(LocalDateTime.now().toString() + ": " + log);
        // 保持最近100条日志
        if (systemLogs.size() > 100) {
            systemLogs.remove(0);
        }
        this.lastModified = LocalDateTime.now();
    }
    
    /**
     * 添加备份记录
     */
    public void addBackupRecord(String backupPath) {
        if (recentBackups == null) {
            recentBackups = new ArrayList<>();
        }
        recentBackups.add(LocalDateTime.now().toString() + ": " + backupPath);
        // 保持最近20条备份记录
        if (recentBackups.size() > 20) {
            recentBackups.remove(0);
        }
        this.lastModified = LocalDateTime.now();
    }
    
    /**
     * 重置为默认设置
     */
    public void resetToDefaults() {
        this.theme = "light";
        this.primaryColor = "#673ab7";
        this.accentColor = "#ff4081";
        this.enableAnimations = true;
        this.enableSoundEffects = true;
        this.defaultJudgeCount = 5;
        this.minScore = 0.0;
        this.maxScore = 100.0;
        this.enableSmartScoring = true;
        this.enableScoreValidation = true;
        this.showDetailedScores = true;
        this.autoBackup = true;
        this.backupInterval = 24;
        this.maxBackupFiles = 10;
        this.enableDataCompression = true;
        this.enableDataEncryption = false;
        this.requirePasswordChange = false;
        this.passwordMinLength = 6;
        this.sessionTimeout = 30;
        this.enableLoginLogging = true;
        this.enableAuditTrail = true;
        this.enableEmailNotifications = false;
        this.enableSystemNotifications = true;
        this.enableAIAnalysis = true;
        this.enableRealTimeSync = false;
        this.enableCloudBackup = false;
        this.cloudProvider = "none";
        this.enablePerformanceMonitoring = true;
        this.lastModified = LocalDateTime.now();
    }
}
